package io;
/**
 * 将io中文件复制到项目中
 */

import java.io.*;

public class Test04 {
    public static void main(String[] args) throws IOException {
        File dir = new File("./src/main/java/io");
        File[] subs = dir.listFiles(f->f.getName().endsWith(".java"));
        int i= 0;
        long st = System.currentTimeMillis();
        for (File sub : subs){
            i++;
            FileInputStream fis = new FileInputStream(sub);
            BufferedInputStream bis = new BufferedInputStream(fis);
            long len = sub.length();
            byte[] date = new byte[(int) len];
            bis.read();
            FileOutputStream fos = new FileOutputStream(sub.getName());
            BufferedOutputStream bos = new BufferedOutputStream(fos);
            int d ;
            long start = System.currentTimeMillis();
            while ((d=fis.read())!=-1){
                bos.write(date,0,d);
            }
            long end = System.currentTimeMillis();
            System.out.println("第"+i+"次复制完毕,共耗时"+(end-start)+"ms");
            bis.close();
            bos.close();
        }
        long en = System.currentTimeMillis();
        System.out.println("复制完毕共耗时"+(en-st)+"ms");

    }
}
